#!/usr/bin/env python
import sys
sys.path.append("/work/opt/analytic/my_python/lib")
from lib.format_time import *
from lib.switch_code import *
from jpype import *
import glob
import sys
import re
import os
sys.setdefaultencoding('utf-8')

class Service58(object):
    def __init__(self):
        self.jars = ':'.join(glob.glob('/work/opt/analytic/my_python/java_lib/imc/*.jar'))
        self.jvm_path = '/opt/soft/java/jre/lib/amd64/server/libjvm.so'
        startJVM(self.jvm_path,"-ea","-Djava.class.path=%s" % self.jars)
        self.SCFInit =JClass("com.bj58.spat.scf.client.SCFInit")
        self.SCFInit.init('/work/opt/analytic/my_python/config/scf.config')
        
        URL= "tcp://imc/InfoProviderWithIndex"            
        self.ProxyFactory =JClass("com.bj58.spat.scf.client.proxy.builder.ProxyFactory")
        #self.IProductService =JClass("com.bj58.sfft.imc.cntity.Info")
        self.Info =JClass("com.bj58.sfft.imc.contract.IInfoService")
        self.Integer =JClass("java.lang.Integer")
        self.String =JClass("java.lang.String")
        self.proxy = self.ProxyFactory.create(self.Info,URL)
        self.out = JClass("com.bj58.spat.scf.server.contract.entity.Out")
        #self.out_total = self.out()
        print "ok"
        
    def get_info(self,info_id): #
        self.infoID = long(info_id)
        #self.query = "state=1&userid=%s"%user_Id
        #GetInfo(long infoID, String columns)
        #print self.infoID
        self.info_model = self.proxy.GetInfo(self.infoID,"params,cateid,url,state,locals,userip")
        
        return self.info_model
    
    def get_info_list(self, condition,page_size,page_num):
        self.cond = condition
        self.total = self.out()
        self.total.setOutPara(0)
        
        return self.proxy.GetInfo(self.cond,"infoid,locals",page_size,page_num,self.total)
    
    
    def update_info(self,info_id,ts ):
        self.infoID = long(info_id)     
        self.proxy.SetInfoTop(self.infoID, ts) 
    
    
    def shut_down(self):
        shutdownJVM()